﻿using ELab.Communication.Events;
using ELab.Communication.Messages;
using ELab.Core;
using ELab.Message;
using ELab.Serialization.Data;
using ELab.SystemWatcher;
using log4net;
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.ServiceProcess;

namespace ELab.Server
{
    public partial class LabServer : ServiceBase
    {
        private static readonly ILog Logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
        private readonly ELabServer _mdsServer;
        public LabServer()
        {
            InitializeComponent();
            _mdsServer = new ELabServer();
        }

        protected override void OnStart(string[] args)
        {
            try
            {
                _mdsServer.Start();
            }
            catch (Exception ex)
            {
                Logger.Fatal(ex.Message, ex);
                Stop();
            }
        }

        protected override void OnStop()
        {
            try
            {
                _mdsServer.Stop(true);
            }
            catch (Exception ex)
            {
                Logger.Warn(ex.Message, ex);
            }
        } 
    }
}
